package Teacher

import (
	"fmt"
)

type Department struct {
	ID          string
	Name        string
	Description string
}

type Teacher struct {
	Age        int
	ID         int
	Name       string
	Gender     string
	Department Department
	Teachers   []Teacher
}

var teachers []Teacher // 全局变量，用于存储所有教师信息

func (department Department) DepartmentPrinter() {
	fmt.Println("-------------------------")
	fmt.Printf("部门ID：%s\n", department.ID)
	fmt.Printf("部门名称：%s\n", department.Name)
	fmt.Printf("部门描述：%s\n", department.Description)
	fmt.Println("-------------------------")
}

func (teacher Teacher) TeachersPrinter() {
	fmt.Println("-------------------------")
	fmt.Printf("教师姓名：%s\n", teacher.Name)
	fmt.Printf("教师性别：%s\n", teacher.Gender)
	fmt.Printf("教师年龄：%d\n", teacher.Age)
	fmt.Printf("教师部门：%s\n", teacher.Department.Name)
	fmt.Println("-------------------------")
	teacher.Department.DepartmentPrinter()
}

func GetTeacherInformation() [3]Teacher {
	var teachers [3]Teacher

	dept1 := Department{
		ID:          "1",
		Name:        "计算机科学与技术",
		Description: "计算机科学与技术系",
	}
	dept2 := Department{
		ID:          "2",
		Name:        "计算机科学与技术",
		Description: "计算机科学与技术系",
	}
	dept3 := Department{
		ID:          "3",
		Name:        "计算机科学与技术",
		Description: "计算机科学与技术系",
	}

	teachers[0] = Teacher{
		ID:         1,
		Name:       "张三",
		Age:        30,
		Gender:     "男",
		Department: dept1,
	}
	teachers[1] = Teacher{
		ID:         2,
		Name:       "李四",
		Age:        28,
		Gender:     "女",
		Department: dept2,
	}
	teachers[2] = Teacher{
		ID:         3,
		Name:       "王五",
		Age:        35,
		Gender:     "男",
		Department: dept3,
	}

	for _, Teacher := range teachers {
		Teacher.TeachersPrinter()
	}
	return teachers
}

func InsertTeacherInformation() {
	var id int
	var name string
	var age int
	var gender string
	var departmentlName string
	var description string

	fmt.Print("请输入教师ID: ")
	fmt.Scan(&id)
	fmt.Print("请输入教师姓名: ")
	fmt.Scan(&name)
	fmt.Print("请输入教师年龄: ")
	fmt.Scan(&age)
	fmt.Print("请输入教师性别: ")
	fmt.Scan(&gender)
	fmt.Print("请输入教师部门名称: ")
	fmt.Scan(&departmentlName)
	fmt.Print("请输入教师部门描述: ")
	fmt.Scan(&description)

	// 创建一个新的 department 实例
	newDept := Department{
		ID:          fmt.Sprintf("%d", id),
		Name:        departmentlName,
		Description: description,
	}

	newTeacher := Teacher{
		ID:         id,
		Name:       name,
		Age:        age,
		Gender:     gender,
		Department: newDept,
	}

	// 将新教师添加到全局 teachers 切片中
	teachers = append(teachers, newTeacher)

	fmt.Println("教师信息已添加成功。")

	// 打印教师信息
	newTeacher.TeachersPrinter()

	// 打印部门信息
	newDept.DepartmentPrinter()
}

func PrintAllTeachers() {
	if len(teachers) == 0 {
		fmt.Println("当前没有教师信息。")
		return
	}
	for _, teacher := range teachers {
		teacher.TeachersPrinter()
	}
}
